package com.study.shop.controller;

import com.study.shop.entity.common.R;
import com.study.shop.entity.dto.LoginDTO;
import com.study.shop.entity.dto.UserDTO;
import com.study.shop.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/acl/index")
@RequiredArgsConstructor
public class AdminController {
    private final UserService userService;

    /**
     * 用户登陆
     *
     * @param loginDTO 账号密码
     * @return 用户信息
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginDTO loginDTO) {
        String token = userService.login(loginDTO);
        return R.success(token);
    }

    // 获取登陆用户信息
    @GetMapping("/info")
    public R info(@RequestHeader("token") String token) {
        UserDTO userDTO = userService.info(token);
        return R.success(userDTO);
    }

    // 退出登陆
    @DeleteMapping("/logout")
    public R logout(@RequestHeader("token") String token) {
        userService.logout(token);
        return R.success();
    }

}
